home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
uw_1.exe
/
STR_DEMO.C
< prev
next >
Wrap
Text File
|
1992-11-12
|
20KB
|
488 lines
/****************************************************************************/
/* */
/* STR_DEMO.C */
/* */
/* We have had several customers experience difficulty understanding the */
/* wn_gets function. This is understandable, it is somewhat confusing. */
/* This demo will help you understand the features, including several new */
/* powerful features, and implement simpler forms to get basic items */
/* such as time, date, phone numbers, etc. The modified wn_gets is fully */
/* compatible with the previous version so none of your code need change. */
/* However, a new function called wn_gets_ll (which wn_gets calls) */
/* has added the capability to uppercase the first char of each word, */
/* strip the mask completely, only strip the end, or not strip at all. */
/* It can also get input right-to-left, clear the entry on the first valid */
/* key, and return when the last character of the input is typed. */
/* Most importantly, it can allow the input of a string longer than the */
/* display width of the field and will scroll within this region auto- */
/* matically! It can also display arrows to show the user that the string */
/* has data to the left or right of the current display field. */
/* */
/* Two newer capabilities of wn_gets_ll are the validation function hook, */
/* which can be called on each valid key pressed, and the gets hook, which */
/* is called on wn_gets_ll entry, exit, and for every key pressed. We will */
/* use the validation hook to show how you can do simple date validation, */
/* and we will use the gets hook to print out the text, mask and template */
/* strings for each key pressed, as well as make the F1 key perform a clear */
/* on the input. */
/* */
/* Note: Compile this file with the warning "parameter 'ident' is never */
/* used" turned off, as we don't have to actually use each parameter */
/* included in the validation and gets hook functions. */
/* */
/*------------------------- flags for wn_gets_ll ---------------------------*/
/* */
/* G_STRIP strips the entire mask from the string. */
/* * 12/04/91 = 120491, (432)-555-3421 = 4325553421 */
/* */
/* G_STRIP_END strips the end of the string only only. */
/* * John Doe______ = John Doe */
/* */
/* G_UP_FST_CHAR converts the first letter of each word to uppercase. */
/* * this is a test = This Is A Test */
/* */
/* G_ARROW displays left and right arrows if display width is less */
/* than field width. NOTE: This requires an additional */
/* screen/window space before and after the field. */
/* */
/* G_RIGHT_TO_LEFT gets input from the right side of the string, scooting */
/* characters over to the left for each valid press. */
/* */
/* G_CLEAR_ON_FIRST clears out the entry when the first valid key is */
/* pressed. This saves a CTRL-Y keystroke to clear the */
/* entry. */
/* */
/* G_EXIT_ON_FILL causes the routine to exit whenever the last valid key */
/* is pressed. This saves an extra <Enter> press. */
/* */
/*--------------------------------------------------------------------------*/
/* */
/* Understanding these few flags and looking at the below examples make */
/* a very complex input routine much more managable! */
/* */
/****************************************************************************/
#include <stdlib.h>
#include "uw.h"
#include "uw_globx.h"
#include "uw_keys.h"
/*-------------------------- a few global variables ------------------------*/
WINDOW Main_wn;
char name1[32], name2[32], name3[32],
phone1[16], phone2[16], phone3[16],
date1[16], date2[16], date3[16],
time1[16], time2[16], time3[16];
/*-------------------------- just some prototypes --------------------------*/
void msg_line( char *msg );
int my_gets(char *s, int max_len, int disp_width, int flags, int clear, WINDOW *wnp);
int my_get_phone(char *s, int disp_width, int flags, WINDOW *wnp);
int my_get_date(char *s, int disp_width, int flags, int clear, WINDOW *wnp);
int my_get_time(char *s, int disp_width, int flags, WINDOW *wnp);
int date_vld(char *w, char *t, char *m, int pos, int max_pos, WINDOW *wnp );
int time_vld(char *w, char *t, char *m, int pos, int max_pos, WINDOW *wnp );
int super_hook( char *text, char *template, char *mask, int pos,
int max_pos, int p_flag, EVENT *eventp, WINDOW *wnp );
/*********/
/* ~main */
/* ********************************************************************/
/****************************************************************************/
int main()
{
int r;
WINDOW *wnp;
init_video(80, 25);
init_clock(0x3333);
wnp = &Main_wn;
wn_create( 0, 0, V_cols-1, V_rows-1, DBL_BDR, WN_NORMAL, wnp );
wn_color( WHITE, BLUE, wnp );
wn_bdr_color( WHITE, BLUE, wnp );
wn_set(wnp);
wnp->inside = OFF;
wn_plst(CENTERED, 0, "<<< EnQue's String Entry Demonstration >>>", wnp);
wn_color(LIGHTGRAY, BLUE, wnp);
wn_plst(CENTERED, 1, "F1 is translated to CTRL-Y and parameters displayed by the new gets hook.", wnp);
/* NOTE:
When we use set_gets_hook or set_validation_func, we can just call the
name of the function when using good old "C", but we have to do the
wild-looking function pointer cast when we use the C++ compiler.
If you rename this "C" file to a "CPP" file and compile under Turbo or
Borland C++ you will get a "Type mismatch in parameter func_ptr"
compiler error (not warning) if you just use the function name without
the cast!
*/
#ifdef __cplusplus
set_gets_hook( (int (*)(...)) super_hook );
#else
set_gets_hook( super_hook );
#endif
wn_color( WHITE, BLUE, wnp );
wnp->inside = ON;
/*---------- display full width and convert first char to uppercase --------*/
r = 2;
msg_line("Entry with first letters capped and no strip");
wn_plst( 2, r, "Enter your name : ", wnp );
my_gets(name1, 22, 22, G_UP_FST_CHAR, 1, wnp);
wn_plst( 50, r, name1, wnp );
/*----------- display full width with strip to end and exit on fill --------*/
r++;
msg_line("Entry with strip to end and exit on fill");
wn_plst( 2, r, "Enter your name : ", wnp );
my_gets(name2, 22, 22, G_STRIP_END | G_EXIT_ON_FILL, 1, wnp);
wn_plst( 50, r, name2, wnp );
/*---------- display only 6 characters, strip the entire mask, -------------*/
/*---------- convert first char, and display arrows... -------------*/
r++;
msg_line("Entry with first letters capped, strip, scrolling, and arrow chars